package com.caocaog.market.entity;

import com.baomidou.mybatisplus.annotation.TableField;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import org.jeecg.common.aspect.annotation.Dict;
import org.springframework.format.annotation.DateTimeFormat;

import javax.validation.constraints.NotBlank;
import java.io.Serializable;
import java.util.Date;
import java.util.List;

/**
 * 市场调研基础信息
 * 此为 MartResearch 和 MartResearchHis 的父类
 *
 * @author chechen
 * @date 2021-01-13
 */
@Data
@NoArgsConstructor
@Accessors(chain = true)
@EqualsAndHashCode(callSuper = false)
@ApiModel
public class MartResearchBase implements Serializable {
    private static final long serialVersionUID = 1L;

    @ApiModelProperty(value = "创建人")
    protected String createBy;

    @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME)
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    @ApiModelProperty(value = "创建时间")
    protected Date createTime;

    @ApiModelProperty(value = "更新人")
    protected String updateBy;

    @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME)
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    @ApiModelProperty(value = "更新时间")
    protected Date updateTime;

    @TableField(update = "%s+1")
    @ApiModelProperty(value = "版本号", hidden = true)
    protected Integer lockVersion;

    @NotBlank(message = "调研标题不能为空")
    @ApiModelProperty(value = "调研标题")
    private String title;

    @NotBlank(message = "调研内容不能为空")
    @ApiModelProperty(value = "调研内容")
    private String researchContent;

    /**
     * 市场调研组集合
     * 此选项就是 researchContent 的 JSON 实例化
     */
    private transient List<ResearchContentGroup> content;

    @Dict(dictTable = "mk_site_basic",dicText = "name",dicCode = "id")
    @ApiModelProperty(value = "分站id")
    private String siteId;

    public MartResearchBase(MartResearchBase martResearchBase) {
        this.createBy = martResearchBase.createBy;
        this.createTime = martResearchBase.createTime;
        this.updateBy = martResearchBase.updateBy;
        this.updateTime = martResearchBase.updateTime;
        this.lockVersion = martResearchBase.lockVersion;
        this.title = martResearchBase.title;
        this.researchContent = martResearchBase.researchContent;
        this.siteId = martResearchBase.siteId;
    }

    public void clearFields () {
        this.createBy = null;
        this.createTime = null;
        this.updateBy = null;
        this.updateTime = null;
    }
}
